import {baseURL} from './config.js'
let ajaxNum = 0
export default function request(options){
  ajaxNum++
  wx.showLoading({
    title: '正在加载',
  })
  // 判断url中是否有/my/请求的路径 带上header token
  let header = {...options.header}
  if(options.url.includes("/my/")){
    //拼接header带上token
    header["Authorization"] = wx.getStorageSync('token')
  }
  return new Promise((resolve,reject)=>{
    wx.request({
      url:baseURL+options.url,
      method:options.method || 'get',
      data:options.data || {},
      success:resolve,
      fail:reject,
      header:header||{},
      complete:()=>{
        ajaxNum--
        if(ajaxNum===0){
          wx.hideLoading()
        }
        
      }
    })
  })
}